package com.study.util;

import java.util.ArrayList;
import java.util.List;


public class Page<T> implements java.io.Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 453425639223842590L;

	private List<T> items = new ArrayList<T>();

	private int totalCount = 0;

	private int pageNum = 0;

	private long pageSize = 0;


	public Page(){}

	public Page(List<T> items, int totalCount) {
		super();
		this.items = items;
		this.totalCount = totalCount;
	}

	public Page(int pageNum, long pageSize, int totalCount, List<T> items) {
		super();
		this.items = items;
		this.totalCount = totalCount;
		this.pageNum = pageNum;
		this.pageSize = pageSize;
	}


	public List<T> getItems() {
		return items;
	}
	public void setItems(List<T> items) {
		this.items = items;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getPageNum() {
		return pageNum;
	}
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public long getPageSize() {
		return pageSize;
	}

	public void setPageSize(long pageSize) {
		this.pageSize = pageSize;
	}

	private int totalPage;

	public int getTotalPage() {
		if(pageSize==0)
			return 0;
		int count = (int)(totalCount / pageSize);
		if (totalCount % pageSize > 0)
			count++;
		totalPage = count;
		return totalPage;
	}

	@Override
	public String toString() {
		return "Page [items=" + items + ", totalCount=" + totalCount
				+ ", pageNum=" + pageNum + ", pageSize=" + pageSize + "]";
	}

}
